package com.game.sdk.popwindow;

import com.game.sdk.util.Constants;
import com.game.sdk.util.MResource;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.PopupWindow;
import android.view.ViewGroup.LayoutParams;

public class SelectPopupWindow extends PopupWindow {

	private Button btn_cancel, bind_phone;
	private View mMenuView;
	private Activity atx;

	public SelectPopupWindow(Activity context, OnClickListener itemsOnClick) {
		super(context);
		atx = context;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(MResource.getIdByName(context,
				Constants.Resouce.LAYOUT, "account_safe_tips_layout"), null);
		btn_cancel = (Button) mMenuView.findViewById(MResource.getIdByName(
				context, Constants.Resouce.ID, "bind_cancle"));
		// 取消按钮
		btn_cancel.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// 销毁弹出框
				dismiss();
				atx.finish();
			}
		});
		bind_phone = (Button) mMenuView.findViewById(MResource.getIdByName(
				context, Constants.Resouce.ID, "bind_phone"));
		bind_phone.setOnClickListener(itemsOnClick);
		// 设置SelectPicPopupWindow的View
		this.setContentView(mMenuView);
		// 设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(LayoutParams.FILL_PARENT);
		// 设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(LayoutParams.FILL_PARENT);
		// 设置SelectPicPopupWindow弹出窗体可点击
		
		// 设置SelectPicPopupWindow弹出窗体动画效果
		this.setAnimationStyle(MResource.getIdByName(context,
				Constants.Resouce.STYLE, "AnimBottom"));
		// 实例化一个ColorDrawable颜色为半透明
		// ColorDrawable dw = new ColorDrawable(0xb0000000);
		ColorDrawable dw = new ColorDrawable(0x00000000);
		// 设置SelectPicPopupWindow弹出窗体的背景
		this.setBackgroundDrawable(dw);
		// mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
		this.setOutsideTouchable(false);// 不可点击在window之外
		this.setOutsideTouchable(false);// 不可点击在window之外
		this.setOnDismissListener(new OnDismissListener() {
			@Override
			public void onDismiss() {
				atx.finish();
			}
		});
	}

}